<template>
<div style="background-color:rgb(235.9, 245.3, 255);width:374px;height:150px;border-radius: 10px;border: #409EFF 1px dashed;padding: 5px;position: absolute;top:10px;left:0px;">
            <textarea
              class="custom-textarea"
              placeholder="可尝试用科目+知识点+难度+题量组成习题要求告诉小敏，例如：请生成高中数学导数低难度的习题10道。"
              v-model="input"
            ></textarea>
            <el-button type="primary" style="position: absolute;top:165px;left:0px;width:100%;height:40px;border-radius: 10px;font-size: 17px;" @click="getQuestion">一键生成</el-button>
          </div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
const input = ref('');

import axios from 'axios'

const emit = defineEmits<{
  (e: 'changeState', param: boolean): void;
  (e: 'changeInternetState',param:boolean):void;
  (e: 'changeDrawer',param:boolean):void
}>();

import { useCounterStore } from '@/stores/counter';
const Store = useCounterStore();
function getQuestion(){
  emit('changeState', true);
  emit('changeInternetState', true);
  axios({
    url:"https://m1.apifoxmock.com/m1/5997017-0-default/teacher/exercise/generatedbytext",
    method:'GET',
    data:{
      text:input.value,
    }
  }).then((response)=>{
    if(response.data.code===1){
      emit('changeState', false)
      console.log("生成的题目为"+response.data.data.exercise)
      Store.getQuestion(response.data.data.exercise)
      emit('changeDrawer',false)//关闭抽屉
    }else{
      //获取失败后的行为
      console.log("生成失败")
      emit('changeState', false)
      emit('changeInternetState', false);
    }
  }).catch(error => {
      alert("出现" + error + "错误，请重新操作")
      emit('changeState', false)
      emit('changeInternetState', false);
    })
    emit('changeDrawer',false)
}
</script>
<style scoped>
.custom-textarea {
  background-color: rgb(235.9, 245.3, 255);
  font-size: 16px;
  height: 90%;
}
</style>